<template>
	<view class="content">
		<!-- <button class="btns" type="primary" @tap="openAddres">默认打开地址</button> -->

		<!-- <button class="btns" type="default" @tap="openAddres2">自定义：根据省市区名称打开地址</button> -->

		<!-- <button class="btns" type="warn" @tap="openAddres3">自定义：根据省市区“code”打开地址</button> -->
		<!-- <textarea v-model="pickerText" cols="30" rows="10"></textarea> -->
		<!--
		 mask-bg-color="rgba(0, 229, 238, 0.4)" // 自定义遮罩层背景颜色
		 -->
		<simple-address ref="simpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"
			themeColor="#007AFF"></simple-address>
		<input class="uni-input" type="text" v-model="tip" placeholder="请选择" @tap="openAddres" disabled />
	</view>
</template>

<script>
	import simpleAddress from '@/components/simple-address/simple-address.nvue';
	export default {
		data() {
			return {
				cityPickerValueDefault: [0, 0, 1],
				pickerText: '',
				tip: ''
			};
		},
		components: {
			simpleAddress
		},
		methods: {
			openAddres() {
				this.cityPickerValueDefault = [0, 0, 0]
				this.$refs.simpleAddress.open();
			},
			openAddres2() {
				// 根据 label 获取
				var index = this.$refs.simpleAddress.queryIndex(['甘肃省', '天水市', '曾都区'], 'label');
				//console.log(index);
				this.cityPickerValueDefault = index.index;
				this.$refs.simpleAddress.open();
			},
			openAddres3() {
				// 根据value 获取
				var index = this.$refs.simpleAddress.queryIndex([13, 1302, 130203], 'value');
				//console.log(index);
				this.cityPickerValueDefault = index.index;
				this.$refs.simpleAddress.open();
			},
			onConfirm(e) {
				e.provinceCode = e.provinceCode + '0000'
				e.cityCode = e.cityCode + '00'
				this.pickerText = JSON.stringify(e);
				this.tip = e.label
				this.$emit('done', e)
			}
		}
	}
</script>

<style lang="less">
	
</style>
